The square brackets expression is called a predicate and it acts as a filter on the nodeset that results from the expression up until the predicate occurs - so in your example, the first expression (using the and operator) the processor will collect all <cd> elements and then for each of them, check if it has a <country> node with the value 'USA' and a <price> node with a value greater than 10.
In the other example, it will find all <cd> elements with a 'USA' <country> node, and only between those, check for a <price> greater than 10.
So, you see - if the [price > 10] was a more expensive operation (e.g., calling an extension function like DateGreaterThanOrEqualToday(), etc.) it's a good idea to only have that expression evaluated when necessary.
Who can tell me what is different between [a=1 and b=1] and [a=1][b=1]?
<xsl:for-each select="catalog/cd[country='USA' and price > 10]">
<xsl:for-each select="catalog/cd[country='USA'][ price > 10]">
above two ways, the results will be the same, what is different of them?
Hi sun,
Very good question :-)
The square brackets expression is called a predicate and it acts as a filter on the nodeset that results from the expression up until the predicate occurs - so in your example, the first expression (using the and operator) the processor will collect all <cd> elements and then for each of them, check if it has a <country> node with the value 'USA' and a <price> node with a value greater than 10.
In the other example, it will find all <cd> elements with a 'USA' <country> node, and only between those, check for a <price> greater than 10.
So, you see - if the [price > 10] was a more expensive operation (e.g., calling an extension function like DateGreaterThanOrEqualToday(), etc.) it's a good idea to only have that expression evaluated when necessary.
Hope that explains it.
/Chriztian
is working on a reply...